package com.changgou.config.controller;

import com.changgou.config.pojo.Cities;
import com.changgou.config.service.CitiesService;
import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/cities")
public class CitiesController {


    @Autowired
    private CitiesService citiesService;


    /***
     * 根据省份ID查询
     * @param provinceId
     * @return
     */
    @GetMapping("/{provinceId}")
    public Result findById(@PathVariable String provinceId){
        try {
            List<Cities> cities = citiesService.findById(provinceId);
            return new Result(true, StatusCode.OK,"查询成功",cities);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }


}
